﻿<%@ WebHandler Language="C#" Class="Upload" %>

using System;
using System.Web;
using System.IO;

public class Upload : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        context.Response.Expires = -1;
        string filename = String.Empty;
        try
        {
            HttpPostedFile postedFile = context.Request.Files["Filedata"];

            string yid = context.Request.QueryString["yid"];

            string abc = HttpUtility.UrlDecode(yid, System.Text.Encoding.Unicode);
            string savepath = string.Empty;
            string tempPath = string.Empty;
            if (!String.IsNullOrEmpty(context.Request.QueryString.Get("logo")))
            {
                tempPath = context.Server.MapPath("../logos") + @"\" + yid;
                filename = "logo_" + yid + ".swf";
            }
            else if (!String.IsNullOrEmpty(context.Request.QueryString.Get("frame")))
            {
                tempPath = context.Server.MapPath("../images/framebg") + @"\" + yid;
                filename = "frame_" + yid + ".gif";
            }
            else
            {
                tempPath = context.Server.MapPath("../logos") + @"\" + yid;
                filename = "figure_" + yid + ".swf";
            }

            if (!Directory.Exists(tempPath))
            {
                Directory.CreateDirectory(tempPath);
            }

            postedFile.SaveAs(tempPath + @"\" + filename);
            context.Response.StatusCode = 200;
            context.Response.Write("1");
        }
        catch (Exception ex)
        {
            context.Response.Write("Error: " + ex.Message);
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}